package com.topscomm.mpm.script;

import com.topscomm.mpm.pojo.MpmProjectChangeEntity;
import com.topscomm.mpm.pojo.MpmProjectEntity;
import com.topscomm.mpm.service.impl.MpmProjectChangeService;
import com.topscomm.mpm.service.impl.MpmProjectRiskService;
import com.topscomm.mpm.service.impl.MpmProjectService;
import com.topscomm.mpm.service.impl.MpmProjectStakeholderService;

import org.springframework.transaction.annotation.Transactional;

import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.mpm.MpmScript;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;

public class MpmProjectStakeholderScript extends MpmScript {

    /**
     * @param service
     * @param entity
     * @throws Exception
     * @Title: projectApproval
     * @description: 更新相关方领导、决策组人员
     * @author: liuchenguang
     * @date: 2021年8月31日
     * @modify:
     */
    @Transactional
    public void stakeholderUpdate(ITapService service, TapEntity entity) throws Exception {
        // 审批节点实例
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        String sourceid = ConvertUtil.convertToString(nodeins.getSourceid());
        MpmProjectChangeService mpmProjectChangeService = (MpmProjectChangeService) SpringUtil
            .getBean("mpmProjectChangeService");
        MpmProjectStakeholderService mpmProjectStakeholderService = (MpmProjectStakeholderService) SpringUtil
            .getBean("mpmProjectStakeholderService");
        MpmProjectChangeEntity mpmProjectChangeEntity = mpmProjectChangeService.queryById(sourceid);
        // 修改相关方人员
        mpmProjectStakeholderService.addProjectLeaderInfo(mpmProjectChangeEntity.getProjectcode2());
    }

    /**
     * @param service
     * @param entity
     * @throws Exception
     * @Title: projectApproval
     * @description: 立项时添加相关方领导、决策组人员
     * @author: liuchenguang
     * @date: 2021年9月3日
     * @modify:
     */
    @Transactional
    public void addStakeholder(ITapService service, TapEntity entity) throws Exception {
        // 审批节点实例
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        String sourceid = ConvertUtil.convertToString(nodeins.getSourceid());
        MpmProjectService mpmProjectService = (MpmProjectService) SpringUtil
            .getBean("mpmProjectService");
        MpmProjectStakeholderService mpmProjectStakeholderService = (MpmProjectStakeholderService) SpringUtil
            .getBean("mpmProjectStakeholderService");
        MpmProjectRiskService mpmProjectRiskService = (MpmProjectRiskService) SpringUtil.getBean("mpmProjectRiskService");
        //查询项目entity
        MpmProjectEntity mpmProjectEntity = mpmProjectService.queryById(sourceid);

        // 修改相关方人员
        mpmProjectStakeholderService.addProjectLeaderInfo(mpmProjectEntity.getProjectcode());
    }
}
